package io.github.siltal.examsystembackend.controller;

import io.github.siltal.examsystembackend.dto.*;
import io.github.siltal.examsystembackend.service.UserService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/user")
public class UserController {

    private final UserService userService;

    public UserController(UserService userService) {
        this.userService = userService;
    }


    @PostMapping("/register")
    public ResponseEntity<?> register(@RequestBody RegisterRequest registerRequest) {
        RegisterResponse res = userService.createUser(registerRequest);
        return ResponseEntity.status(HttpStatus.OK).body(res);
    }

    @PostMapping("/login")
    public ResponseEntity<?> login(@RequestBody LoginRequest loginRequest) {
        LoginResponse res = userService.login(loginRequest);
        return ResponseEntity.status(HttpStatus.OK).body(res);
    }

    @PostMapping("/password_change")
    public ResponseEntity<?> passwordChange(@RequestBody PasswordChangeRequest request) {
        PasswordChangeResponse res = userService.passwordChange(request);
        return ResponseEntity.status(HttpStatus.OK).body(res);
    }

    @PostMapping("/email_change")
    public ResponseEntity<?> emailChange(@RequestBody EmailChangeRequest request) {
        EmailChangeResponse res = userService.emailChange(request);
        return ResponseEntity.status(HttpStatus.OK).body(res);
    }



    /*
    @GetMapping("/get_user")
    TODO 未鉴权不应当开放查询用户信息
    public ResponseEntity<RegisterResponse> getUserById(@Param("id") Long id) {
        return userService.getUserById(id)
            .map(user -> ResponseEntity.ok(RegisterResponse.fromUser(user)))
            .orElse(ResponseEntity.notFound().build());
    }
    */


}